//
//  BKColleageViewModel.m
//  baokaodaxue
//
//  Created by dangyangyang on 15/6/2.
//  Copyright (c) 2015年 宏图教育. All rights reserved.
//

#import "BKColleageViewModel.h"
#import <AFNetworking.h>

@implementation BKColleageViewModel


+ (void)jianjieWithCid:(NSString *)cid success:(void (^)(NSDictionary *))success failure:(void (^)(NSString *))failure{

    NSDictionary *params = @{@"cid":cid};
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/cjianjie"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSDictionary *dic = responseDic[@"extraData"];
                 
                 
                 success(dic);
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];

}

+ (void)xuekeWithCid:(NSString *)cid success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure{

    NSDictionary *params = @{@"cid":cid};
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/cxueke"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *array = responseDic[@"extraData"];
                 
                 
                 success(array);
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
    

}

+ (void)huanjingWithCid:(NSString *)cid type:(NSString *)type success:(void (^)(NSArray *))success failure:(void (^)(NSString *))failure{

    NSDictionary *params = @{@"cid":cid,@"type":type};
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/cphotos"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSArray *array = responseDic[@"extraData"];
                 
                 
                 success(array);
                 
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
                 
             }
             
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
    
    

}

+ (void)lishifenshuWithCid:(NSString *)cid kaoquId:(NSString *)kaoqu success:(void (^)(NSDictionary *))success failure:(void (^)(NSString *))failure
{
    NSDictionary *params = @{@"cid":cid,@"kq":kaoqu};
    
    
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    [manager.requestSerializer setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    
    [manager GET:@"http://www.baokaodaxue.com/bk/mobile/FenShu3"
      parameters:params
         success:^(AFHTTPRequestOperation *operation, id responseObject) {
             NSDictionary *responseDic=[NSJSONSerialization
                                        JSONObjectWithData:responseObject
                                        options:NSJSONReadingMutableLeaves
                                        error:nil];
             if ([[responseDic objectForKey:@"code"] isEqualToString:@"200"]) {
                 
                 NSDictionary *dict = responseDic[@"extraData"];
                 success(dict);
                 
             }else{
                 failure([responseDic objectForKey:@"message"]);
             }
         }
         failure:^(AFHTTPRequestOperation *operation, NSError *error) {
             failure(@"网络连接失败");
         }];
}

@end
